class Strategy {
  // 是否必填
  String require(value, String message) {
    return (value == null || value == '' || value == 0) ? message : '';
  }

  // 正则匹配
  String pattern(String value, RegExp reg, String message) {
    return reg.hasMatch(value) ? '' : message;
  }

  // 最小长度
  String minLength(value, int len, String message) {
    if (value is String) {
      return value.length >= len ? '' : message;
    }
    if (value is int || value is double) {
      var _number = value.toDouble();
      return _number >= len ? '' : message;
    }
    return message;
  }

  // 最大长度
  String maxLength(value, int len, String message) {
    if (value is String) {
      return value.length <= len ? '' : message;
    }
    if (value is int || value is double) {
      var _number = value.toDouble();
      return _number <= len ? '' : message;
    }
    return message;
  }
}
